package cate.game.play.skill.passive.hero;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.HeroFighter;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 当队伍总血量低于70%时，净化自身，并进入【潜行】，每场战斗触发1次。
 */
public class 净心九命PH extends PassiveHandler {


	private double 血量;

	private int buff;

	//血量=7000&buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getWDouble("血量", 0d);
		buff = args.getInt("buff",0);
	}

	private boolean addBuff;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (addBuff) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		double hp = 0d;
		double hpMax = 0d;
		for (HeroFighter allHero : skill.owner.getFightTeam().getAllHero()) {
			hp += allHero.attr.total().hpCur();
			hpMax += allHero.attr.total().hpTotal();
		}
		if (hpMax <= 0) {
			return;
		}
		if (hp / hpMax >= 血量) {
			return;
		}
		addBuff = true;
		skill.owner.buff.tryAddByTid(action, buff);
	}
}
